package com.aceleeyy.aceleespringcloudalibaba.service.impl;

        import com.aceleeyy.aceleespringcloudalibaba.service.HelloService;
        import com.alibaba.csp.sentinel.annotation.SentinelResource;
        import com.alibaba.csp.sentinel.slots.block.BlockException;
        import lombok.extern.slf4j.Slf4j;
        import org.springframework.stereotype.Service;

/**
 * TODO
 *
 * @author Ace Lee
 * @date 2019/9/23 14:54
 * @version 1.0
 **/
@Slf4j
@Service
public class HelloSericeImpl implements HelloService {


    @SentinelResource(value = "doSomething", blockHandler = "exceptionHandler")
    @Override
    public void doSomething(String s) {
        System.out.println("doSomething------------"+s);
    }


    @SentinelResource(value = "doSomething2", fallback = "fallbackHandler")
    @Override
    public void doSomething2(String s) {
        log.info("doSomething2------------"+s);
        throw new RuntimeException("发生异常");
    }

    // 限流与阻塞处理
    public void exceptionHandler(String str, BlockException ex) {
        log.error( "blockHandler：" + str, ex);
    }

    // 熔断与降级处理
    public void fallbackHandler(String str) {
        log.error("fallbackHandler：" + str);
    }
}
